﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using System.Threading.Tasks;
using Xc.DataAccess.Core;
using Xc.DataAccess.DataBase.DeviceInfos;
using Xc.DataAccess.Protocoals.WaterMeters.Models;
using Xc.DataAccess.Protocoals.WaterMeters.Models.Responds;
using Xc.DataAccess.WaterMeters.ClientSides.Services;

namespace Xc.DataAccess.WaterMeters.ClientSides.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeviceController : ControllerBase
    {
        private readonly IWaterDeviceReceiveService _waterMeterDeviceService;
        public DeviceController(IWaterDeviceReceiveService waterMeterDeviceService)
        {
            _waterMeterDeviceService = waterMeterDeviceService;
        }
        /// <summary>
        /// 读取表计地址
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetMeterAddressRespond([FromBody] GetMeterAddressRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.GetMeterAddressRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 获取表具数据应答回调
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetMeterDataRespond([FromBody] GetMeterDataRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.GetMeterDataRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 设备主动上传
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> MeterAutoUploadRespond([FromBody] MeterAutoUploadRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.MeterAutoUploadRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 设置囤积量和报警量应答
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetAlarmVolumeRespond([FromBody] SetAlarmVolumeRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetAlarmVolumeRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 关阀控制应答
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetCloseValveRespond([FromBody] SetCloseValveRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetCloseValveRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 设置目标服务器IP地址
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetMeterIpAddressRespond([FromBody] SetMeterIpAddressRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetMeterIpAddressRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 多次卡充值应答
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetMeterMutipleChargeRespond([FromBody] SetMeterMutipleChargeRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetMeterMutipleChargeRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 修改上报周期和超时限制
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetMeterUploadIntervalRespond([FromBody] SetMeterUploadIntervalRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetMeterUploadIntervalRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 设置表计底数
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetMeterValueRespond([FromBody] SetMeterValueRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetMeterValueRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 开阀控制应答
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetOpenValveRespond([FromBody] SetOpenValveRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetOpenValveRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 恢复出厂设置表计应答
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetRestoreFactoryRespond([FromBody] SetRestoreFactoryRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetRestoreFactoryRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
        /// <summary>
        /// 用户充值应答
        /// </summary>
        /// <param name="respond"></param>
        /// <param name="frameCommand"></param>
        /// <param name="dataSegment"></param>
        /// <param name="devcieId"></param>
        /// <param name="meterType"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SetUserChangeRespond([FromBody] SetUserChangeRespond respond, FrameCommand frameCommand, DataSegment dataSegment, string devcieId, MeterType meterType, byte companyId)
        {
            return await _waterMeterDeviceService.SetUserChangeRespond(respond, frameCommand, dataSegment, devcieId, meterType, companyId);
        }
    }
}
